﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using Model;

namespace DAL
{
    public class generic_goodsDal
    {
        /// <summary>
        /// 查商品库资料
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static ms_generic_goods Querybycode(string code)
        {
            string sql = "select * from ms_generic_goods where gg_bar_code=@gg_bar_code";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("gg_bar_code", code);
            ms_generic_goods gd = new ms_generic_goods();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            if (rd.Read())
            {
                gd.gg_bar_code = rd["gg_bar_code"].ToString();
                gd.gg_goods_name = rd["gg_goods_name"].ToString();
                gd.gg_cover = rd["gg_cover"].ToString();
                gd.gg_carousel = rd["gg_carousel"].ToString();
                gd.gg_market_price = rd["gg_market_price"].ToString();
                gd.gg_describes = rd["gg_describes"].ToString();
                gd.gg_introduce = rd["gg_introduce"].ToString();
                gd.gg_brand = rd["gg_brand"].ToString();
                gd.gg_production_license_number = rd["gg_production_license_number"].ToString();
                gd.gg_product_standard_number = rd["gg_product_standard_number"].ToString();
                gd.gg_manufacturer = rd["gg_manufacturer"].ToString();
                gd.gg_specs = rd["gg_specs"].ToString();
                gd.gg_producer = rd["gg_producer"].ToString();
                gd.gg_guarantee = rd["gg_guarantee"].ToString();
                gd.gg_weight = rd["gg_weight"].ToString();
                gd.gg_add_time = rd["gg_add_time"].ToString();
            }
            rd.Close();
            return gd;
        }
        /// <summary>
        /// 查所有商品
        /// </summary>
        /// <returns></returns>
        public static List<ms_generic_goods> Querylist()
        {
            string sql = "select * from ms_generic_goods where gg_goods_name is not null";
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, null);
            List<ms_generic_goods> gdlist = new List<ms_generic_goods>();
            while (rd.Read())
            {
                ms_generic_goods gd = new ms_generic_goods();
                gd.gg_bar_code = rd["gg_bar_code"].ToString();
                gd.gg_goods_name = rd["gg_goods_name"].ToString();
                gd.gg_cover = rd["gg_cover"].ToString();
                gd.gg_carousel = rd["gg_carousel"].ToString();
                gd.gg_market_price = rd["gg_market_price"].ToString();
                gd.gg_describes = rd["gg_describes"].ToString();
                gd.gg_introduce = rd["gg_introduce"].ToString();
                gd.gg_brand = rd["gg_brand"].ToString();
                gd.gg_production_license_number = rd["gg_production_license_number"].ToString();
                gd.gg_product_standard_number = rd["gg_product_standard_number"].ToString();
                gd.gg_manufacturer = rd["gg_manufacturer"].ToString();
                gd.gg_specs = rd["gg_specs"].ToString();
                gd.gg_producer = rd["gg_producer"].ToString();
                gd.gg_guarantee = rd["gg_guarantee"].ToString();
                gd.gg_weight = rd["gg_weight"].ToString();
                gd.gg_add_time = rd["gg_add_time"].ToString();
                gdlist.Add(gd);
            }
            rd.Close();
            return gdlist;
        }
    }
}
